//
//  QMAContextDelegate.h
//  Pods
//
//  Created by elvisgao on 2019/11/27.
//

#import <Foundation/Foundation.h>
#import <Photos/Photos.h>
#import "QMADelegateDefine.h"
#import "MABaseApplication.h"
#import "QMAModelUtils.h"

NS_ASSUME_NONNULL_BEGIN

@protocol QMAContextDelegate <NSObject>

@optional
/// 打印Log
/// @param level log级别，参考PLTLogLevel
/// @param msg log信息
- (void)log:(MALogLevel)level msg:(NSString *)msg;

/// 解压zip
/// @param sourcePath zip包路径
/// @param dstPath 目标路径
/// @param error 解压失败的error
- (BOOL)unzipFileFromPath:(NSString *)sourcePath toDstPath:(NSString *)dstPath withError:(NSError **)error;

/// 从选图器选择媒体
/// @param model 配置
/// @param parentVC vc
/// @param completionBlock 选择完毕后需要回传数据 根据所选类型接受 QMAPickerImageModel QMAPickerVideoModel
- (void)selectMediaFromPickerWithModel:(QMAMediaChooseConfigModel *)model
                              parentVC:(UIViewController *)parentVC
                       completionBlock:(void(^)(NSArray * _Nullable medias, NSError * _Nullable error))completionBlock;

/// 拍摄媒体
/// @param model 配置
/// @param parentVC vc
/// @param completionBlock 选择完毕后需要回传数据，根据所选类型接受QMACameraImageModel QMACameraVideoModel
- (void)selectMediaFromCameraWithModel:(QMAMediaChooseConfigModel *)model
                              parentVC:(UIViewController *)parentVC
                       completionBlock:(void(^)(id _Nullable media, NSError * _Nullable error))completionBlock;

/// 从PHAsset中获取图片数据
/// @param phAsset 媒体对象
/// @param needCompress 是否需要压缩
- (NSData *)imageDataFromPhAsset:(PHAsset *)phAsset needCompress:(BOOL)needCompress;

/// 打开文档预览
/// @param filePath 文档路径
/// @param titleName 标题
/// @param application 小程序/小游戏实例 导航栏为application.rootViewController
- (void)openDocument:(NSString *)filePath
               title:(NSString *)titleName
         application:(MABaseApplication *)application;

/// 图片预览
/// @param navigationController 呼起图片预览的导航栏
/// @param currentAbsoluteUrl 当前页面地址
/// @param absUrlsInPreviewArray 需要预览的图片
- (void)navigationController:(UINavigationController *)navigationController
  presentImageWithCurrentUrl:(NSString *)currentAbsoluteUrl
               imageUrlArray:(NSArray *)absUrlsInPreviewArray;

/// 创建WebViewController
/// @param model 参数model
- (UIViewController *)createWebViewController:(QMAWebViewVCModel *)model;
/// 创建 hippy VC
/// @param dic 传入 hippy 启动参数 详见 https://iwiki.woa.com/pages/viewpage.action?pageId=419651325
- (UIViewController *)createHippyController:(NSDictionary *)dic;

/// 获取当前位置
/// @param completionBlock 回调
- (void)requestLocation:(MALocationCompletionBlock)completionBlock;

/// 上传appID对应小程序的log
/// 实现时，可以使用MiniAppSDK的`sandBoxPathWithAppID:`接口获取沙箱路径，然后拼接`usr/miniprogramLog/`获取
/// @param appID 小程序/小游戏的appID
- (void)uploadLogFileWithAppID:(NSString *)appID;

/// 系统默认的UA，即不做任何定制时的UA
/// for web-view组件使用
- (NSString *)defaultUserAgent;

#pragma mark - 本地图片加载

/// 获取需要下载的imageView
/// @param url 图片地址
- (nullable UIImageView *)imageViewWithURL:(NSString *)url;

/// 创建imageView
/// @param frame frame
/// @param src 支持网络图片和本地图片
- (UIImageView *)createImageViewWithRect:(CGRect)frame src:(NSString *)src;

/// 更新imageView的资源路径
/// @param imageView 更新对象
/// @param src 支持网络图片和本地图片
- (void)updateImageView:(UIImageView *)imageView src:(NSString *)src;

/// 半屏的loadingView
- (nullable UIView *)halfScreenLoadingView;

#pragma mark -

// TODO: 需要将字典抽成model

/// 扫码调用客户端的扫码模块scancode
/// @param scanPrams 扫码参数字典
/// @param navigationController 从那个页面呼起vc
/// @param completionHandler 回调结果
- (void)scanCode:(NSDictionary *)scanPrams
navigationController:(UINavigationController *)navigationController
completionHandler:(MACommonCallback)completionHandler;

/// 钱包支付
/// @param app 小程序/小游戏实例
/// @param params 参数
/// @param completionHandler 回调结果
- (void)openWalletPay:(MABaseApplication *)app params:(NSDictionary *)params completionHandler:(MACommonCallback)completionHandler;

#pragma mark - 设备相关

/// 开始加速度传感器更新
- (void)startAccelerometerUpdates;

/// 关闭加速传感度更新
- (void)stopAccelerometerUpdates;

/// 当前设备方向
- (UIDeviceOrientation)curDeviceOrientation;

#pragma mark - 小程序/小游戏状态

/// 点击了小程序/小游戏
/// @param app 小程序/小游戏实例
/// @param scene 场景值
- (void)clickMiniApp:(MABaseApplication *)app scene:(MAEntryScene)scene;

/// 当前小程序发生改变
/// @param application 小程序/小游戏实例
- (void)onMiniAppChanged:(MABaseApplication *)application;

/// 将Application的生命周期处理透传出来，业务再去处理各自逻辑
/// @param app 小程序/小游戏实例
/// @param type 状态
- (void)lifeCycleForApp:(MABaseApplication *)app type:(QMAAppLifeCycleType)type;

/// 栈上所有小程序/小游戏被移除
- (void)allAppInStackRemoved;

// 小游戏最多存活的实例个数
- (NSInteger)maxMiniGameInstanceCount;

@end

NS_ASSUME_NONNULL_END
